package com.situ.login.controller;

import com.situ.login.entity.SysUser;
import com.situ.login.entity.quanxian;
import com.situ.login.service.LoginService;
import com.situ.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.List;

@RestController
public class LoginContrpller  {
    @Autowired
    private LoginService ls;


    @GetMapping("/logincrm")
    public ResponseData Login(SysUser u){
    try {
    SysUser users =ls.LoginUser(u.getUsr_Name(), u.getUsr_Password());
        String backpoint="";//返回值
      //user不为空时
        if(users!=null){

            //状态不可用时
            if(users.getUsr_Flag()==0||users.getRole_Flag()==2){
                backpoint="当前角色不可用";
            }
            //状态可用时
            if(users.getUsr_Flag()!=0&&users.getRole_Flag()!=2){
                backpoint="成功";
            }
        }else{//user为空时
            System.out.print("密码或用户名错误！");
            backpoint="密码或用户名错误！";
        }
    return ResponseData.ok().putDataValue("backpoint",backpoint).putDataValue("users", users);
    }catch (Exception e){
        e.printStackTrace();
        return ResponseData.serverInternalError();
    }
}


@GetMapping("/qureyParentList")
public ResponseData qureyParentList(Integer roleid){
        List<quanxian> list=ls.queryParentList(roleid);
        return ResponseData.ok().putDataValue("parentList",list);

    }

}
